package correct.day13;

import java.util.Scanner;

public class Test1 {

    public static void main() {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- != 0)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            char[] s = in.next().toCharArray();

            int ret = 0;
            for(int i = 0; i < s.length; i++)
            {
                if(s[i] == 'L')
                    ret -= 1;
                else
                {
                    if(i - 1 >= 0 && i - 2 >= 0 && s[i - 1] == 'W' && s[i - 2] == 'W')
                    {
                        ret += k;
                    }
                    else
                    {
                        ret += 1;
                    }
                }
            }
            System.out.println(ret);
        }
    }

    public static void main2(String[] args) {
        Scanner in = new Scanner(System.in);
        int t = in.nextInt();
        while(t-- != 0)
        {
            int n = in.nextInt();
            int k = in.nextInt();
            char[] s = in.next().toCharArray();

            int ret = 0;
            for(int i = 0; i < s.length; i++)
            {
                if(s[i] == 'L')
                    ret -= 1;
                else
                {
                    if(i - 1 >= 0 && i - 2 >= 0 && s[i - 1] == 'W' && s[i - 2] == 'W')
                    {
                        ret += k;
                    }
                    else
                    {
                        ret += 1;
                    }
                }
            }
            System.out.println(ret);
        }
    }

    public static void main1(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        for(int i = 0; i < T; i++) {
            int n = scanner.nextInt();
            int k = scanner.nextInt();
            String s = scanner.next();
            char[] arr = s.toCharArray();
            int count = 0;
            for(int j = 0; j < arr.length; j++) {
                if(arr[j] == 'W') {
                    if(j > 1 && arr[j - 1] == 'W' && arr[j - 2] == 'W') {
                        count += k;
                    }else {
                        count++;
                    }
                }else {
                    count--;
                }
            }
            System.out.println(count);
        }
    }
}
